﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SiteAdmin_MainMenu : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void MainMenu_MenuItemDataBound(object sender, MenuEventArgs e)
    {
        if (!ConfigManager.Debug)
        {
            e.Item.Enabled = SecurityValid(e.Item.Text, e.Item.NavigateUrl);
        }
        if (e.Item.Depth == 0)
        {
            e.Item.Enabled = true;
        }
        e.Item.Text = "<span style='cursor:pointer;'>" + e.Item.Text + "</span>";
        if (!e.Item.Enabled)
        {
            e.Item.Text = "<span style='cursor:default; color:#808080;'>" + e.Item.Text + "</span>";
        }
    }

    private bool SecurityValid(string subject, string url)
    {
        if (string.IsNullOrEmpty(url)) return true;

        bool flag = false;
        foreach (DataRow row in SessionManager.DataSetRule.Tables[0].Rows)
        {
            if (!string.IsNullOrEmpty(row["ContainerName"].ToString()) &&
                url.ToLower().IndexOf(row["ContainerName"].ToString().ToLower()) > -1)
            {
                flag = true;
                break;
            }
        }
        return flag;
    }
}
